//
//  NSAttributedString+Extension.swift
//  Weibo
//
//  Created by 王惠平 on 2017/4/9.
//  Copyright © 2017年 Will Wang. All rights reserved.
//

import UIKit

extension NSAttributedString {
    
    //根据表情模型创建表情富文本
    class func attributedStringWithEmoticon(emoticon: VVEmoticon,font: UIFont) -> NSAttributedString {
       
        
        //1.创建图片对象
        let image = UIImage(named: emoticon.path!)
        
        //2.创建文本附件设置图片
        let attachMent = VVTextAttachment()
        
        //设置图片
        attachMent.image = image
        
        //设置表情模型
        attachMent.emoticon = emoticon
        
        //获取字体的高度
        let lineHeight = font.lineHeight
        
        //设置图片大小
        //设置bounds改变子控件显示位置
        attachMent.bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        
        //3.根据文本附件创建富文本
        let attrbuteStr = NSAttributedString(attachment: attachMent)
        
        return attrbuteStr
        
    }
   
}
